<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" th:href="@{/xadmin/css/font.css}">
    <link rel="stylesheet" th:href="@{/xadmin/css/xadmin.css}">
    <script th:src="@{/xadmin/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/xadmin/js/xadmin.js}"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        .layui-table-body {
            overflow-x: hidden;
        }
    </style>
</head>

<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">演示</a>
                <a>
                    <cite>导航元素</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <table class="layui-table" id="test" lay-filter="test"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <div class="layui-inline" title="添加" lay-event="add"><i class="layui-icon layui-icon-add-1"></i></div>
    </div>
</script>
<script>
    layui.use(['table', 'form'], function () {
        var table = layui.table;
        var form = layui.form;
        var load = layer.load(1);
        getTable();
        layer.close(load);

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'add':
                    xadmin.open('添加', '/houseparent/getPage?name=notice-add');
                    break;
            }
        });

        table.on('tool(test)', function (obj) {
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    var load = layer.load(2)
                    $.ajax({
                        url: '/noticeApartment',
                        type: "DELETE",
                        data: {id: obj.data.id},
                        dataType: 'json',
                        success: function (result) {
                            layer.close(load)
                            if (result.code === 500 || result.code === 5000100 || result.code === 5000101 || result.code === 5000102) {
                                layer.alert(result.msg, {icon: 2});
                            } else {
                                layer.alert("删除成功", {icon: 1}, function (index1) {
                                    layer.close(index1);
                                    //xadmin.father_reload();
                                    table.reload('test');
                                });
                            }
                        },
                    });

                });
            } else if (obj.event === 'edit') {
                // console.log($(window).width())
                xadmin.open('修改', '/noticeApartment/edit?id=' + obj.data.id);
            }
        });

        function getTable() {
            table.render({
                elem: '#test',
                url: '/noticeApartment',
                toolbar: '#toolbarDemo',
                cols: [
                    [
                        {type: 'numbers', width: 80, sort: true, title: '序号'},
                        {field: 'title', minWidth: 200, title: '标题'},
                        {field: 'submitter', minWidth: 60, title: '提交人'},
                        {
                            field: 'createTime',
                            minWidth: 180,
                            templet: '<div>{{layui.util.toDateString(d.createTime*1, `yyyy-MM-dd HH:mm:ss`)}}</div>',
                            title: '提交时间'
                        },
                        {toolbar: '#barOptional', minWidth: 100, title: '操作'}
                    ]
                ],
                page: true,
                limits: [10, 20, 50, 100, 500, 1000]
            });
        }
    });
</script>
<script type="text/html" id="barOptional">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>&nbsp;
</script>
</html>